##### Script Purpose ------------------------------ 
# Wrangles the tidy dataframe and creates categorization variables for later
# this script needs the tidy rds file generated by the prior script, 
#   1-import dictionary tidy.R

##### Load Packages ------------------------------ 
library(tidyverse)

##### Import Data ------------------------------ 
df <- readRDS("tidy_df.rds")


##### Categorizing Issues by Morality Paradigm
# This paper explores a two-category morality policy paradigm and a three-category paradigm

# Create the two-category variable (moral vs non-moral)
df <- df %>% 
  mutate(twocategory = recode_factor(issue, 
                                     `abortionfunds` = "non-moral", 
                                     `banssmarriage` = "moral", 
                                     `deathpenalty` = "moral", 
                                     #`deathpenaltydenom` = "moral", 
                                     `medicalpot` = "moral", 
                                     `minimumwage` = "non-moral", 
                                     `officialenglish` = "non-moral", 
                                     `pasuicide` = "moral", 
                                     `propertytaxlimit` = "non-moral", 
                                     `recreationpot` = "non-moral",
                                     `righttowork` = "non-moral",
                                     `tribalgaming` = "non-moral")) %>% 
  mutate(twocategory = fct_relevel(twocategory, "non-moral"))

# Another idea is that it's three categories (non-moral/mixed/moral)
# Create the three category idea
df <- df %>% 
  mutate(threecategory = recode_factor(issue, 
                                       `abortionfunds` = "mixed", 
                                       `banssmarriage` = "moral", 
                                       `deathpenalty` = "moral", 
                                       #`deathpenaltydenom` = "moral", 
                                       `medicalpot` = "moral", 
                                       `minimumwage` = "non-moral", 
                                       `officialenglish` = "mixed", 
                                       `pasuicide` = "moral", 
                                       `propertytaxlimit` = "non-moral", 
                                       `recreationpot` = "mixed", 
                                       `righttowork` = "mixed", 
                                       `tribalgaming` = "mixed")) %>% 
  mutate(threecategory = fct_relevel(threecategory, "non-moral"))



##### Export wrangled data ------------------------------ 
# Basic transformations are done, now save as RDS object for future scripts
saveRDS(df, "wrangled_df.rds")


